#ifndef __draw__helper__h__
#define __draw__helper__h__
#include "fixed_lookuptbl.h"

inline unsigned int duRGBA(int r, int g, int b, int a)
{
	return ((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16) | ((unsigned int)a << 24);
}

inline unsigned int duRGBAf(float fr, float fg, float fb, float fa)
{
	unsigned char r = (unsigned char)(fr * 255.0f);
	unsigned char g = (unsigned char)(fg * 255.0f);
	unsigned char b = (unsigned char)(fb * 255.0f);
	unsigned char a = (unsigned char)(fa * 255.0f);
	return duRGBA(r, g, b, a);
}

unsigned int duIntToCol(int i, int a);
void duIntToCol(int i, float* col);

inline unsigned int duMultCol(const unsigned int col, const unsigned int d)
{
	const unsigned int r = col & 0xff;
	const unsigned int g = (col >> 8) & 0xff;
	const unsigned int b = (col >> 16) & 0xff;
	const unsigned int a = (col >> 24) & 0xff;
	return duRGBA((r * d) >> 8, (g * d) >> 8, (b * d) >> 8, a);
}

inline unsigned int duDarkenCol(unsigned int col)
{
	return ((col >> 1) & 0x007f7f7f) | (col & 0xff000000);
}

inline unsigned int duLerpCol(unsigned int ca, unsigned int cb, unsigned int u)
{
	const unsigned int ra = ca & 0xff;
	const unsigned int ga = (ca >> 8) & 0xff;
	const unsigned int ba = (ca >> 16) & 0xff;
	const unsigned int aa = (ca >> 24) & 0xff;
	const unsigned int rb = cb & 0xff;
	const unsigned int gb = (cb >> 8) & 0xff;
	const unsigned int bb = (cb >> 16) & 0xff;
	const unsigned int ab = (cb >> 24) & 0xff;

	unsigned int r = (ra * (255 - u) + rb * u) / 255;
	unsigned int g = (ga * (255 - u) + gb * u) / 255;
	unsigned int b = (ba * (255 - u) + bb * u) / 255;
	unsigned int a = (aa * (255 - u) + ab * u) / 255;
	return duRGBA(r, g, b, a);
}

inline unsigned int duTransCol(unsigned int c, unsigned int a)
{
	return (a << 24) | (c & 0x00ffffff);
}

unsigned int areaToCol(unsigned int area);
enum DrawNavMeshFlags
{
	DU_DRAWNAVMESH_OFFMESHCONS = 0x01,
	DU_DRAWNAVMESH_CLOSEDLIST = 0x02,
	DU_DRAWNAVMESH_COLOR_TILES = 0x04,
};

void dd_vertex(const fixed64& vx, const fixed64& vy, const fixed64& vz, unsigned int c, FPRaw* vp, int& vl, unsigned int* cp, int& clen,int vmax,int cmax);
#endif//__draw__helper__h__